package com.hongpu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hongpu.domain.CoolTowerEmployeeSalaryProjectRelationship;
import com.hongpu.mapper.CoolTowerEmployeeSalaryProjectRelationshipMapper;
import com.hongpu.service.CoolTowerEmployeeSalaryProjectRelationshipService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

/**
 * @author Michael zhang
 * @description 针对表【cool_tower_employee_salary_project_relationship(冷却塔安装人员薪资与安装项目关联关系)】的数据库操作Service实现
 * @createDate 2025-06-12 08:52:59
 */
@Service
public class CoolTowerEmployeeSalaryProjectRelationshipServiceImpl extends ServiceImpl<CoolTowerEmployeeSalaryProjectRelationshipMapper, CoolTowerEmployeeSalaryProjectRelationship>
        implements CoolTowerEmployeeSalaryProjectRelationshipService {


    @Autowired
    CoolTowerEmployeeSalaryProjectRelationshipMapper baseMapper;

    /**
     * 根据人员ID查询所在的项目列表
     *
     * @param employeeId
     */
    @Override
    public IPage<CoolTowerEmployeeSalaryProjectRelationship> selectPage(IPage ipage, Long employeeId) {
        try {
            return baseMapper.selectPage(ipage, employeeId);
        } catch (Exception e) {
            e.printStackTrace();
            return ipage;
        }
    }

    /**
     * 获取当前项目的基本工资
     *
     * @param coolTowerProjectId
     * @param coolTowerEmployeeId
     */
    @Override
    public BigDecimal selectSalary(Long coolTowerProjectId, Long coolTowerEmployeeId) {
        try {
            return baseMapper.selectSalary(coolTowerProjectId, coolTowerEmployeeId);
        } catch (Exception e) {
            e.printStackTrace();
            return BigDecimal.ZERO;
        }
    }

    /**
     * 从数据库中获取两个日期夸几个月
     *
     * @param startDate
     * @param endDate
     */
    @Override
    public int selectMonth(String startDate, String endDate) {
        try {
            return baseMapper.selectMonth(startDate, endDate);
        } catch (Exception e) {
            e.printStackTrace();
            return 0;
        }
    }

    /**
     * 根据人员ID和项目ID查询数据库中是否已经存在数据
     *
     * @param coolTowerEmployeeId
     * @param coolTowerProjectId
     */
    @Override
    public boolean isExistData(Long coolTowerEmployeeId, Long coolTowerProjectId) {
        try {
            return baseMapper.isExistData(coolTowerEmployeeId, coolTowerProjectId);
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }

    /**
     * 向  cool_tower_employee_salary_project_relationship 表中插入一条数据
     *
     * @param coolTowerEmployeeId 员工ID
     * @param salary              薪资，取值于人员信息表
     * @param dailySettlementFee  日结费用，取值于人员信息表
     * @param subsidy             补助，数据来自cool_tower_employee（保留字段）
     * @param coolTowerProjectId  项目ID
     * @return
     */
    @Override
    public int insert(Long coolTowerEmployeeId, BigDecimal salary, BigDecimal dailySettlementFee, BigDecimal subsidy, Long coolTowerProjectId) {
        try {
            // 向 cool_tower_employee_salary_project_relationship 表中插入一条数据
            CoolTowerEmployeeSalaryProjectRelationship coolTowerEmployeeSalaryProjectRelationship = new CoolTowerEmployeeSalaryProjectRelationship();
            coolTowerEmployeeSalaryProjectRelationship.setCoolTowerEmployeeId(coolTowerEmployeeId).setSalary(salary).setDailySettlementFee(dailySettlementFee)
                    .setSubsidy(subsidy).setCoolTowerProjectId(coolTowerProjectId);
            return baseMapper.insert(coolTowerEmployeeSalaryProjectRelationship);
        } catch (Exception e) {
            e.printStackTrace();
            return 0;
        }
    }

    /**
     * 从cool_tower_employee_salary_project_relationship 表中获取员工在项目上的工数及各种费用
     *
     * @param coolTowerEmployeeId
     * @param coolTowerProjectId
     */
    @Override
    public CoolTowerEmployeeSalaryProjectRelationship selectEmployeeSalaryProjectRelationship(Long coolTowerEmployeeId, Long coolTowerProjectId) {
        CoolTowerEmployeeSalaryProjectRelationship employeeSalaryProjectRelationship = new CoolTowerEmployeeSalaryProjectRelationship();
        try {
            QueryWrapper<CoolTowerEmployeeSalaryProjectRelationship> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("cool_tower_employee_id", coolTowerEmployeeId).eq("cool_tower_project_id", coolTowerProjectId);
            employeeSalaryProjectRelationship = baseMapper.selectOne(queryWrapper);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return employeeSalaryProjectRelationship;
    }
}




